<template>
    <List class="table_desc1" header="公司列表"/>
    <Table :columns="columns" :data="companylist">
        <template #name="{ row }">
            <router-link :to="{ path: '/company/detail', query: { id: row.id } }">{{ row.name }}</router-link>
        </template>
    </Table>
    <Page v-model="page.pageIndex" :total="page.totalCount" 
    :page-size="page.pageSize" @on-change="page_change" show-elevator show-total />
</template>
<script>
import axios from 'axios'
// import { useRouter } from 'vue-router'

export default {
    setup() {

    },
    methods: {
        page_change: function() {
            this.fetch_data()
        },
        fetch_data: function () {
            axios.get("http://localhost:3000/company/page_query?page=" + this.page.pageIndex + "&per_page=" + this.page.pageSize)
                .then(resp => {
                    if (resp && resp.data && resp.data.data && resp.data.data.length > 0) {
                        this.companylist = resp.data.data
                        this.page = {
                            pageIndex: resp.data.page,
                            pageSize: resp.data.per_page,
                            pageTotal: resp.data.total_page,
                            totalCount: resp.data.total_count
                        }
                    }
                }).catch(function (error) {
                    console.log(error)
                })
        }
    },
    data() {
        return {
            columns: [
                // {
                //     title: 'ID',
                //     key: 'id'
                // },
                {
                    title: '公司名称',
                    slot: 'name'
                },
                {
                    title: '跟进人',
                    key: 'followup_employee'
                },
                {
                    title: '公司电话',
                    key: 'phone_no'
                },
                {
                    title: '公司邮编',
                    key: 'postal_code'
                },
                {
                    title: '公司地址',
                    key: 'address'
                }
            ],
            companylist: [],
            page: {
                pageIndex: 1,
                pageSize: 10,
                pageTotal: 0,
                totalCount: 0
            }
        }
    },
    mounted() {

    },
    created() {
        this.fetch_data()
    },
}
</script>

